package com.onec.service.io.selector;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

public class NioDisCardClient {


  public static void startClient() throws IOException {

    InetSocketAddress socketAddress = new InetSocketAddress("127.0.0.1", 8852);
    SocketChannel socketChannel = SocketChannel.open(socketAddress);
    socketChannel.configureBlocking(false);
    while (!socketChannel.finishConnect()) {

    }
    System.out.println("链接成功");

    ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
    byteBuffer.put("hello word".getBytes());
    byteBuffer.flip();
    socketChannel.write(byteBuffer);
    socketChannel.shutdownOutput();
    socketChannel.close();
  }

  public static void main(String[] args) throws IOException {
    startClient();
  }
}
